
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');

exports.__esModule = true;
exports.default = void 0;

const _babelHelperVueJsxMergeProps = _interopRequireDefault(require('@vue/babel-helper-vue-jsx-merge-props'));

const _utils = require('../utils');

const _constant = require('../utils/constant');

const _functional = require('../utils/functional');

const _tag = _interopRequireDefault(require('../tag'));

const _icon = _interopRequireDefault(require('../icon'));

const _cell = _interopRequireDefault(require('../cell'));

const _radio = _interopRequireDefault(require('../radio'));

const _button = _interopRequireDefault(require('../button'));

const _radioGroup = _interopRequireDefault(require('../radio-group'));

// Utils
// Components
const _createNamespace = (0, _utils.createNamespace)('contact-list');
const createComponent = _createNamespace[0];
const bem = _createNamespace[1];
const t = _createNamespace[2];

function ContactList(h, props, slots, ctx) {
  const List = props.list && props.list.map((item, index) => {
    function onClick() {
      (0, _functional.emit)(ctx, 'input', item.id);
      (0, _functional.emit)(ctx, 'select', item, index);
    }

    function RightIcon() {
      return h(_radio.default, {
        attrs: {
          name: item.id,
          iconSize: 16,
          checkedColor: _constant.RED,
        },
        on: {
          click: onClick,
        },
      });
    }

    function LeftIcon() {
      return h(_icon.default, {
        attrs: {
          name: 'edit',
        },
        class: bem('edit'),
        on: {
          click: function click(event) {
            event.stopPropagation();
            (0, _functional.emit)(ctx, 'edit', item, index);
          },
        },
      });
    }

    function Content() {
      const nodes = [`${item.name}\uFF0C${item.tel}`];

      if (item.isDefault && props.defaultTagText) {
        nodes.push(h(_tag.default, {
          attrs: {
            type: 'danger',
            round: true,
          },
          class: bem('item-tag'),
        }, [props.defaultTagText]));
      }

      return nodes;
    }

    return h(_cell.default, {
      key: item.id,
      attrs: {
        isLink: true,
        center: true,
        valueClass: bem('item-value'),
      },
      class: bem('item'),
      scopedSlots: {
        icon: LeftIcon,
        default: Content,
        'right-icon': RightIcon,
      },
      on: {
        click: onClick,
      },
    });
  });
  return h('div', (0, _babelHelperVueJsxMergeProps.default)([{
    class: bem(),
  }, (0, _functional.inherit)(ctx)]), [h(_radioGroup.default, {
    attrs: {
      value: props.value,
    },
    class: bem('group'),
  }, [List]), h('div', {
    class: bem('bottom'),
  }, [h(_button.default, {
    attrs: {
      round: true,
      block: true,
      type: 'danger',
      text: props.addText || t('addText'),
    },
    class: bem('add'),
    on: {
      click: function click() {
        (0, _functional.emit)(ctx, 'add');
      },
    },
  })])]);
}

ContactList.props = {
  value: null,
  list: Array,
  addText: String,
  defaultTagText: String,
};

const _default = createComponent(ContactList);

exports.default = _default;
